<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<sfa:mainTitle></sfa:mainTitle>
		<%@ include file="../../../common/meta.jsp"%>
		<link rel="stylesheet" type="text/css" href="${path}/css/step/an.css" />
<script type="text/javascript">

$(function() {	
	fixTable.FixTable("mytable");//控制表单第一行为静态
	
	$("#hide").css("display","none");
	
	$("#nexpStep").click(function() {
    	$("#lastStep").show();
    	$("#saveAffirm").show();
    	$("#return").hide();
    	$(this).hide(); 
    	$(".remark").hide();
    	$(".remarked").show();
    	$(".status").hide();
    	$(".statusSpan").show();
    	$(".remark").each(function(i,obj1){
    		var remark = $(obj1).find(":input:text").val();
    		$(obj1).next().html(remark);
    	})
    	$(".status").each(function(){
			var checkVal = $(this).find("input:checked").next().text(); 
			$(this).next().html(checkVal);
			
    	});
    	
	 	$("#firstStep_line").attr("class","line");
		$("#secondStep").attr("class", "");
		$("#secondStep_line").attr("class","line_last");
		$("#thirdStep").attr("class","now");
		$("#thirdStep_line").attr("class","line_over");
	});
	$("#lastStep").click(function(){
    	$("#nexpStep").show();
    	$("#return").show();
    	$("#saveAffirm").hide();
    	$(this).hide();
    	$(".status").show();
    	$(".statusSpan").hide();
		$(".remark").show();
    	$(".remarked").hide();
    	
    	$("#firstStep_line").attr("class","line_last");
    	$("#secondStep").attr("class", "now");
		$("#secondStep_line").attr("class","line_frist");
		$("#thirdStep").attr("class","");
		$("#thirdStep_line").attr("class","line_end");
	});
	//保存考勤
	$("#saveAffirm").click(function() {
    	var checkitem = $("#checkitem").val();
    	var checktimebegin = $("#checktimebegin").val();
    	var checktimeend = $("#checktimeend").val();
		
    	var checkedVal="";
    	var checkedVal1="";
    	var checkedVal2="";
    	var checkedVal3="";
    	
    	$(".status").each(function(){
    		
    		var id =$(this).attr("val");//获取ID
    		var val =$(this).find("input:checked").val();//获取状态
    		checkedVal += id+"-"+val+"," ; 
    		
    	});
    	$(".agentCode").each(function(i,obj){
    		var agentcode = $(obj).attr("title");//获取员工编号
    		checkedVal1 += agentcode+",";
    	});
    	$(".agentName").each(function(i,obj){
    		var agentname = $(obj).attr("title");//获取员工名字
    		checkedVal2 += agentname+",";
    	});
    	$(".remark").each(function(i,obj){
    		var remark = $(obj).find("input:text").val();
    		checkedVal3 += remark+",";
    	});
    	if(checkedVal){
    		checkedVal = checkedVal.substring(0,checkedVal.length-1);//截取ID和状态后面的逗号
    	}
    	if(checkedVal1){
    		checkedVal1 = checkedVal1.substring(0,checkedVal1.length-1);//截取员工编号后面的逗号
    	}
    	if(checkedVal2){
    		checkedVal2 = checkedVal2.substring(0,checkedVal2.length-1);//截取员工名字后面的逗号
    	}
    	var data = {
    		cheitem : checkitem,
    		chetimebegin : checktimebegin,
			chetimeend : checktimeend,
			cheVal : checkedVal,
			cheVal1 : checkedVal1,
			cheVal2 : checkedVal2,
			cheVal3 : checkedVal3
		};
    	$.ajax({
					url : "${path}/team/attendance/index/insert",
					type : 'POST',
					timeout : 10000,
					dataType: 'json',
					data :data ,
					success: function(result){   
					    //alert(result);
					    var obj = result;
					   // alert(obj.mainid);
						if (obj.result == "true") {
							
							art.dialog( {
								icon : "succeed",
								content : "保存成功!",
								lock : true,
								ok : function() {
					    			window.location.href="${path}/team/attendance/index/thisinto?mainid="+obj.mainid;
								}
							});
						} else {
							art.dialog( {
								icon : "error",
								content : "保存失败!",
								lock : true,
								ok : true
							});
						}
						
					    },   
    				error: function(html){   
					    alert('请联系管理员');
					    alert($(html).html());
					    document.writeln(html);
					}
				});
	});	
});
</script>		
</head>
	<body id="master">
		<sfa:mainHeader></sfa:mainHeader>
		<div class="webpart3 contentarea">
		<div class="webpart-head">
		<div class="webpart-head-item">
		<span> 考勤流程 </span>
		<div style="float:right;margin-right: 10px;">
		<input type="button" class="linkbtn2" value="保存" id="saveAffirm" style="display:none;" />
		<input type="button" class="linkbtn2" value="上一步" id="lastStep" style="display:none;" />
		<input type="button" class="linkbtn2" value="下一步" id="nexpStep" />
		<input type="button" class="linkbtn2" value="上一步" id="return" onclick = "javascript:history.go(-1);">
		</div>
		</div>
		</div>
	<div class="webpart-main">
    	<div class="webpart-main-item"> 	
    	
    			<div class="at_loc" style="padding-top: 12px;">
						<span style="width: 208px;">考勤管理</span>
						<span class="line_last" id="firstStep_line"></span>
						<span class="now" style="width: 208px;" id="secondStep">考勤登记</span>
						<span class="line_frist" id="secondStep_line"></span>
						<span style="width: 208px;" id="thirdStep">考勤确认</span>
						<span class="line_end" id="thirdStep_line"></span>
				</div>			
     		<div class="search" style="height: 341px; overflow: auto;margin-top: 12px;">
				<table id="mytable" border="0" cellspacing="0" cellpadding="0"
					class="sortable trStyleTable dg_borderstyle" style="width: 100%;text-align: center;">
					<thead>
						<tr>
							<th style="width: 80px;">
								考勤编号
							</th>
							<th style="width: 50px;">
								姓名
							</th>
							<th style="width: 80px;">
								 代理人层级 
							</th>
							<th style="width: 220px;">
								 考勤结果 
							</th>
							<th>
								 备注 
							</th>
						</tr>
						</thead>
						<tbody>
						<c:forEach items="${arr}" var="result">
							<tr class="gray datarow" id="tr_${result.agentId}">

								<td>
									<div title="${result.agentCode}" class="agentCode"
										style="width: 80px; overflow: hidden; text-overflow: ellipsis">
										${result.agentCode}
									</div>
								</td>
								<td>
									<div title="${result.agentName}" class="agentName"
										style="width: 50px; overflow: hidden; text-overflow: ellipsis">
										${result.agentName}
									</div>
								</td>
								<td>
									<span>
										<sfa:dic showType="value" code="AGENTLEVELCODE_${result.agentLevel}" def="null:空"></sfa:dic>
									</span>
								</td>
								<td>
										<span class="status" val="${result.agentId}">
										 <sfa:dic showType="radio"
												kindNo="CHECKSTATUS" code="CHECKSTATUS_1"
												name="CHECKSTATUS_${result.agentId}"></sfa:dic>
										</span>		
									<span class="statusSpan"> </span>
								</td>
								<td>
									<span class="remark">
										<input type="text" id="remark" name="remark" size="50"
										style="border: none; width: 100%; height:24px; padding: 0px;"/>
									</span>
									<span class="remarked"> </span>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			
			</div>
	<div id="hide">
    <table border="0" cellspacing="0" cellpadding="0"
					class="sortable trStyleTable dg_borderstyle" style="margin-top: 12px; width: 100%;">
						<tr>
							<td>
								<input type="text" id="checkitem" name="checkitem" value="${checkitem}" />
							</td>
							<td>
								<input type="text" id="checktimebegin" name="checktimebegin"
									value="${checktimebegin}" />
							</td>
							<td>
								<input type="text" id="checktimeend" name="checktimeend"
									value="${checktimeend}" />
							</td>							
						</tr>
	</table>
	</div>
	</div>
	 	<div class="webpart-foot">
           <div class="webpart-foot-item">
           </div>
        </div>
	</div>
	<sfa:mainFooter></sfa:mainFooter>
  </body>
</html>
